﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Noris.Tools.FrxEditor.Components
{
    public class DButton : Button
    {
        public DButton()
        {
            this.TextAlign = ContentAlignment.MiddleCenter;
            this.TextImageRelation = TextImageRelation.ImageBeforeText;
            this.ImageAlign = ContentAlignment.MiddleRight; // MiddleCenter;
        }
    }
    /// <summary>
    /// První odvozený combo box
    /// </summary>
    public class DComboBox : ComboBox
    {
        /// <summary>
        /// Položky nabídky DComboBoxu typované na DComboItem
        /// </summary>
        public IEnumerable<DComboItem> DItems
        {
            get
            {
                List<DComboItem> dItems = new List<DComboItem>();
                foreach (object item in this.Items)
                {
                    DComboItem dItem = item as DComboItem;
                    if (dItem != null)
                        dItems.Add(dItem);
                }
                return dItems;
            }
            set
            {
                this.Items.Clear();
                if (value != null)
                    this.Items.AddRange(value.ToArray());
            }
        }
        /// <summary>
        /// Aktuálně vybraná položka typovaná na DComboItem
        /// </summary>
        public DComboItem SelectedDItem
        {
            get
            {
                return this.SelectedItem as DComboItem;
            }
            set
            {
                this.SelectedItem = value;
            }
        }
        /// <summary>
        /// Metoda najde v položkách Combo boxu objekt s daným ID
        /// </summary>
        /// <param name="findID"></param>
        /// <returns></returns>
        public DComboItem ComboFindDItem(IComparable findID)
        {
            foreach (object item in this.Items)
            {
                DComboItem dItem = item as DComboItem;
                if (dItem != null && dItem.ID.CompareTo(findID) == 0)
                    return dItem;
            }
            return null;
        }
    }
    /// <summary>
    /// Objekt, který nese ID, text a libovolná data.
    /// Typicky jde o položku ListBoxu nebo ComboBoxu, kde se zobrazuje text a současně je obsažen libovolný datový objekt.
    /// </summary>
    public class DComboItem
    {
        public DComboItem(IComparable id)
        {
            this.ID = id;
        }
        public DComboItem(IComparable id, string text)
        {
            this.ID = id;
            this.Text = text;
        }
        public DComboItem(IComparable id, string text, object data)
        {
            this.ID = id;
            this.Text = text;
            this.Data = data;
        }
        public override string ToString()
        {
            return this.Text;
        }
        public IComparable ID { get; set; }
        public string Text { get; set; }
        public object Data { get; set; }
    }
}
